﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}

<style>
    .checkbox {
        margin-top: 10px !important;
        margin-left: 8px !important;
    }
     /*****************/
    .area{float:left;}
    .bread-nav-R{float:right;}
    .bread-nav-R span{color:#2e2e2e;}
    .bread-nav-R span i{padding:0 13px;color:#999;}
    .bread-nav-R span b{padding-left:8px;font-size:16px;color:#4ca6ff;}
    .bread-nav-R span.cwzs b{color:#fd7d7e;}
    .bread-nav-R span.yzrs b{color:#40cc85;}
    .sygzs b{color:#ffb745 !important;}
</style>
<script>
    $(function () {
        gridList();
        initControl();
    });

    function initControl()
    {
        $("#status").bindSelect(); 

        //获取分类
        $("#pcid").bindSelect({
            url: areaName + "/SystemManage/Offer/GetTreeSelectJson",
            id: "PCID",
            text: "NAME"
        });
    }

    function gridList() {
        var $gridList = $("#gridList");
        var JsonPa = '{ "state": "' + $("#state").val() + '", "pcid":"' + $("#pcid").val() + '", "title":"' + $("#title").val() + '" }';
        $gridList.dataGrid({
            url: "/SystemManage/Offer/GetGridJson",
            postData: { JsonPara: JsonPa },
            height: $(window).height() - 96,
            colModel: [
                { label: "主键", name: "OFFERID", hidden: true, key: true },
                { label: '商品标题', name: 'TITLE', width: 500, align: 'center' },
                { label: '规则', name: 'SPECIFICATIONSSTR', width: 50, align: 'center' },
                { label: '单位', name: 'UNIT', width: 50, align: 'center' },
                { label: '会员价', name: 'VIPPRICE', width: 50, align: 'center' },
                { label: '地区', name: 'AREA', width: 60, align: 'center' },
                { label: '库存', name: 'INVENTORYCOUNT', width: 60, align: 'center' },
                {
                    label: '状态', name: 'STATE', width: 50, align: 'center',
                    formatter: function (cellvalue) {
                        if (cellvalue && cellvalue == 0) {
                            return "未上架";
                        } else {
                            return "已上架";
                        }
                    }
                },
                { label: '新增人', name: 'USERNAME', width: 150, align: 'center' }
            ],
            pager: "#gridPager",
            //sortname: 'DINING_NAME',
            viewrecords: true,
            multiselect: true,
            onSelectAll: function () {
                // 操作栏收缩 20170831+
                $(".operate").animate({ "left": '0' }, 200);
                $("#RowCount").html($("#gridList").jqGrid("getGridParam", "selarrrow").length);
            }
        });
        $("#btn_search").click(function () {
            var JsonPa = '{ "state": "' + $("#state").val() + '", "pcid":"' + $("#pcid").val() + '", "title":"' + $("#title").val() + '" }';
            $gridList.jqGrid('setGridParam', {
                postData: { JsonPara: JsonPa },
            }).trigger('reloadGrid');
        });
    }
    
    // 新增
    function btn_add() {
        window.location.href = '/SystemManage/Offer/Form'
    }
    // 详情页
    function btn_details() {
        var keyValue = 0;
        var ids = $("#gridList").jqGrid("getGridParam", "selarrrow");
        if (ids.length < 1) {
            $.modalMsg("请选择分配方案", "warning");
            return false;
        } else if (ids.length > 1) {
            $.modalMsg("无法同时查看多条信息，请单选查看。", "warning");
            return false;
        }
        else
        {
            $(ids).each(function (index, id) {
                keyValue = id;
            })
            window.location.href = '/SystemManage/Offer/Form?keyValue=' + keyValue;
        } 
    }
    // 审核
    function btn_aduit() {
        var keyValue = 0;
        var ids = $("#gridList").jqGrid("getGridParam", "selarrrow");
        if (ids.length < 1) {
            $.modalMsg("请选择分配方案", "warning");
            return false;
        } else if (ids.length > 1) {
            $.modalMsg("不能同时审核多个分配方案", "warning");
            return false;
        }
        else {
            var STATUS = $("#gridList").jqGrid('getRowData', ids[0]).Status;

            if (STATUS == 3) {
                $.modalMsg("该方案已经审核通过", "warning");
                return false;
            } else if (STATUS == 4) {
                $.modalMsg("该方案已经拒绝", "warning");
                return false;
            } else {
                $(ids).each(function (index, id) {
                    keyValue = id;
                })
            }
        }
        $.modalOpen({
            id: "Form",
            title: "方案审核",
            url: areaName + '/AssignManage/Assign/Form?id=' + keyValue,
            width: "380px",
            height: "300px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    //$("#gridList").resetSelection();
    //$("#gridList").trigger("reloadGrid");
    // 删除
    function btn_delete() {
        $.modalConfirm("注：您确定要【删除】选中的分配方案吗？", function (r) {
            if (r) {
                var keyValue = '';
                var ids = $("#gridList").jqGrid("getGridParam", "selarrrow");
                $(ids).each(function (index, id) {
                    var STATUS = $("#gridList").jqGrid('getRowData', id).Status;
                    if (STATUS == 3) {
                        $.modalMsg("选择中存在已经审核通过方案,不能删除", "warning");
                        return false;
                    } else if (STATUS == 2) {
                        $.modalMsg("选择中存在待审核方案,不能删除", "warning");
                        return false;
                    } else {
                        $(ids).each(function (index, id) {
                            keyValue += id + ",";
                        })
                        //keyValue = keyValue ? keyValue.substring(0,keyValue)
                        $.submitForm({
                            url: areaName + '/AssignManage/Assign/DeleteForm',
                            param: { keyValue: keyValue },
                            success: function () {
                                // 操作栏收缩 20170417+
                                $(".operate").animate({ "left": '-100.1%' }, 200);
                                $.currentWindow().$("#gridList").trigger("reloadGrid");
                            }
                        })
                    }
                })
            }
        });
    }
    function ToExcel() {
        var JsonPa = '{ "state": "' + $("#state").val() + '", "pcid":"' + $("#pcid").val() + '", "title":"' + $("#title").val() + '" }';
        window.location.href = areaName + "/AssignManage/AssignAdd/PreAssinToExcel?JsonPara=" + JsonPa;
    }
</script>
<link href="~/Content/css/font-awesome.min.css" rel="stylesheet">
<div class="topPanel clearFix"> 
    <div class="toolbar">
        <div class="btn-group">
            <a class="btn btn-primary" onclick="$.reload()">
                <span class="glyphicon glyphicon-refresh"></span>
            </a>
        </div>
        <div class="btn-group">
            <a id="" class="btn btn-primary dropdown-text" onclick="btn_add()"><i class="fa fa-plus"></i>新建商品</a>
        </div>
        <div class="operate">
            <ul class="nav nav-pills">
                <li class="first">已选中<span>1</span>项</li>
                <li><a id="" onclick="btn_aduit()"><i class="fa fa-pencil-square-o"></i>审核</a></li>
                <li><a id=""  onclick="btn_details()"><i class="fa fa-pencil-square-o"></i>修改</a></li>
                <li><a id=""  onclick="btn_delete()"><i class="fa fa-trash-o"></i>删除</a></li>
                <li><a id=""  onclick="ToExcel()"><i class="fa fa-trash-o"></i>导出</a></li>
            </ul>
            <a href="javascript:;" class="close"></a>
        </div>
        <script>$('.toolbar').authorizeButton()</script>
    </div>
    <div class="search">
        <table>
            <tr>
                <td>分类：</td>
                <td>
                    <div class="input-group" style="width: 135px">
                        <select id="pcid" name="pcid" class="form-control" style="width:120px;">
                            <option value="0">-全部-</option>
                        </select>
                    </div>
                </td>
                <td>状态：</td>
                <td>
                    <div class="input-group" style="width: 135px">
                        <select id="state" name="state" class="form-control" style="width:120px;">
                            <option value="-1">-请选择-</option>
                            <option value="0">-未上架-</option>
                            <option value="1">-已上架-</option>
                        </select>
                    </div>
                </td>
                <td>
                    <div class="input-group">
                        <input id="title" name="title" type="text" class="form-control" placeholder="请输入商品标题" style="width: 150px; margin-left: 5px">
                        <div class="input-group">
                            <span class="input-group-btn">
                                <button id="btn_search" type="button" class="btn  btn-primary"><i class="fa fa-search"></i></button>
                            </span>
                        </div>
                    </div>
</td>
            </tr>
        </table>
    </div>
</div>
<style>
    .Tab-mar table{margin:0 !important;}
    .Tab-mar #gridList{width:100% !important;table-layout: auto !important;}
    .Tab-mar .ui-jqgrid-htable{width:100% !important;}
    .Tab-mar .ui-jqgrid .ui-jqgrid-hbox{padding-right:0 !important;}
</style>
<div class="gridPanel Tab-mar">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>
